﻿using ConstructorAsyncWebApi.Services;

namespace ConstructorAsyncWebApi.ServicesImpl
{
    public class DataCompareService : IDataCompareService
    {
        private readonly IDataSegmentationService _dataSegmentationService;
        private bool _isInitialized;

        private DataCompareService(IDataSegmentationService dataSegmentationService)
        {
            _dataSegmentationService = dataSegmentationService;
        }

        public static async Task<DataCompareService> CreateAsync(IDataSegmentationService dataSegmentationService)
        {
            var dataCompareService = new DataCompareService(dataSegmentationService);
            await dataCompareService.InitializeAsync();
            return dataCompareService;
        }

        private async Task InitializeAsync()
        {
            // 这里是异步初始化逻辑
            await Task.Delay(1000);

            _isInitialized = true;
        }

        public async Task<bool> GetIsInSame()
        {

            var datas1 = await _dataSegmentationService.SegmentationSummarys();
            var datas2 = await _dataSegmentationService.SegmentationIds();

            var countSame = datas1.Count() == datas2.Count();
            if (!countSame)
            {
                return countSame;
            }

            for (int i = 0; i < datas1.Count(); i++)
            {
                var isSame = datas1[i] == datas2[i];
                if (!isSame)
                {
                    return isSame;
                }
            }

            return true;
        }

    }
}
